
<template>


  <div class="img" :style="note">



    <div style="width: 300px;height: 900px;background-color: rgba(0,0,0,0.01);margin:0px auto;text-align: center;position: relative">
      <div style="width: 300px;height: 500px;background-color: rgba(0,0,0,0.6);text-align: center;position: absolute;margin-top: 100px">
        <p style="font-size: 28px;font-family: '楷体';padding-top: 20px;color: slategray">创建小组</p>
        <hr style="width: 90%;height: 0.01px"/>

        <div style="width: 100%">
          <form style="width: 100%">
            <p style="width: 100%;margin-left: 70px; text-align: left;color: slategray">请上传项目图片</p>
            <input type="file" @change="getFile($event)" style="color: slategray">
            <button class="button button-primary button-pill button-small" @click="submit($event)">提交</button>
          </form>
        </div>
        <div >
          <div style="margin-top: 40px"  @keyup.enter="login">
            <el-input v-model="inputName" placeholder="请输入组名" style="width: 70%"></el-input>
            <!--<el-input v-model="inputPassword" type="password" placeholder="请输入密码" style="width: 70%;margin-top: 20px"></el-input>-->
          </div>

          <el-button plain style="margin-top: 40px;width: 100px" size="small" @click="login">创建</el-button>

        </div>


      </div>
    </div>
  </div>
</template>





<script>

  export default {


    data() {
      return {
        note: {
          backgroundImage: "url(" + require("../../assets/img/starrr.jpg") + ")",
          backgroundRepeat: "no-repeat",
          backgroundSize: "1890px 1500px",
        },
        inputName: '',
        photoUrl:''
      }
    },
    watch: {},
    methods: {

      getFile: function (event) {
        this.file = event.target.files[0];
        console.log(this.file);
      },
      submit: function (event) {
        //阻止元素发生默认的行为
        var _this=this
        event.preventDefault();
        let formData = new FormData();
        // console.log(formData)
        formData.append("file", this.file)
        axios.post('/upload/singlefile', formData)
          .then(function (response) {
            //   console.log(response)
            alert("上传成功");
            var a= response.data;
            //  var e=a.split("*");
            //console.log(e[1])
            _this.photoUrl=a;

            // window.location.reload();
          })
          .catch(function (error) {
            alert("上传失败");
            console.log(error);
            //window.location.reload();
          });
      },



      login() {
        var user= JSON.parse(window.sessionStorage.getItem("user"));
        var ff=user.id
        axios.post('/workroom/buildGroup', {
          wid:ff,
          groupname:this.inputName,
          photo:this.photoUrl
        }).then((response) => {
          if (response.data.states ==800) {
            this.$notify({
              title: '成功',
              message: '创建成功',
              type: 'success',
              duration: 2000
            });
            this.$router.replace('/Group')
          }
          else {
            this.$notify.error({
              title: '错误',
              message: response.data.message,
              type: 'warning',
              duration: 0
            });
          }

        }).catch((response) => {
          this.$notify.error({
            title: '错误',
            message: '网络错误'
          });
        })
      }
    }
  }
</script>

<style scoped>

</style>


